<?php
/**
 * Created by PhpStorm.
 * User: 海峡
 * Date: 2021/1/22
 * Time: 9:56
 */
namespace App\Services;

class GoodsClassService extends BaseService
{
    public function get_tree_classes($list, $pid = 0, &$result = array(), $deep = 0)
    {
        $deep += 2;
        foreach ($list as $k=>$v){   //遍历之后，此处的$k是键(其实是数组的序列号)，$v是一条数据结果
            if($v->pid==$pid){
                $result[$k]['id'] = $v->id;
                $result[$k]['name'] = "|".str_repeat("--", $deep).$v->name;
                $result[$k]['pid'] = $v->pid;
                self::get_tree_classes($list, $v->id, $result, $deep);
            }else{
                continue;
            }
        }
        return $result;
    }
}